package com.zyj.rabbitmq.receive;

import com.zyj.rabbitmq.config.RabbitConfig;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


@Component
public class Receiver {

    @RabbitHandler
    @RabbitListener(queues = "hello")
    public void process(String hello) {
        System.out.println("Receiver  : " + hello);
    }

    /**
     * 点对点模式
     * @param p2pQueue
     */
    @RabbitHandler
    @RabbitListener(queues = "p2pQueue")
    public void p2pProcess(String p2pQueue){
        System.out.println("Receiver :" + p2pQueue);
    }

    /**
     * fanout 模式
     * @param message
     * 我们可以通过@RabbitListener监听多个queue来进行消费
     */
    @RabbitHandler
    @RabbitListener(queues = {
            RabbitConfig.FANOUT_A,
            RabbitConfig.FANOUT_B,
            RabbitConfig.FANOUT_C
    })
    public void fanout(String message){
        System.out.println("Receiver :" + message);
    }


    /**
     * topic模式
     */
    @RabbitListener(queues = {
            RabbitConfig.TOPIC,
            RabbitConfig.TOPIC_A,
            RabbitConfig.TOPIC_B
    })
    @RabbitHandler
    public void topic(String message){
        System.out.println("topic-Receiver :" + message);
    }


}
